package com.jenkins.test.stream;

/**
 * @version V1.0.0
 * @ClassName: {@link ExpressCondition}
 * @Description: ExpressCondition
 * @author: Lanzhou
 * @date: 2022/1/21 15:59
 * @Copyright:2020 All rights reserved.
 */
public class ExpressCondition {

    /**
     * @param condition 条件运行语句
     * @return 执行体函数
     */
    public static IfElseCondition decide(boolean condition) {
        return (yes, no) -> {
            if (condition) {
                yes.run();
            } else {
                no.run();
            }
        };
    }

    /**
     * 条件满足就运行:
     * if (condition) run...
     *
     * @param condition 条件
     * @return
     */
    public static IfCondition runIf(boolean condition) {
        return (yes) -> {
            if (condition) {
                yes.run();
            }
        };
    }

    /**
     * 不满足就抛出异常
     *
     * @param condition 条件
     */
    public static ThrowEnable condition(boolean condition) {
        return (errMsg) -> {
            if (condition) {
                throw new RuntimeException(errMsg);
            }
        };
    }


}
